package org.codeart.apipassenger.controller;

import lombok.extern.slf4j.Slf4j;
import org.codeart.apipassenger.service.PriceService;
import org.codeart.common.util.R;
import org.codeart.common.request.EstimatedPriceDTO;
import org.codeart.common.response.PriceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/price")
public class PriceController {
    
    @Autowired
    private PriceService priceService;

    @PostMapping("/estimated")
    public R<PriceResponse> estimatedPrice(@RequestBody EstimatedPriceDTO estimatedPriceDTO) {
        String depLongitude = estimatedPriceDTO.getDepLongitude();
        String depLatitude = estimatedPriceDTO.getDepLatitude();
        String destLongitude = estimatedPriceDTO.getDestLongitude();
        String destLatitude = estimatedPriceDTO.getDestLatitude();
        String cityCode = estimatedPriceDTO.getCityCode();
        String vehicleType = estimatedPriceDTO.getVehicleType();
        log.info("出发地经度: {}", depLongitude);
        log.info("出发地纬度: {}", depLatitude);
        log.info("目的地经度: {}", destLongitude);
        log.info("目的地纬度: {}", destLatitude);
        log.info("调用计价服务，计算价格");
        PriceResponse response = priceService.estimatedPrice(depLongitude, depLatitude, destLongitude, destLatitude, cityCode, vehicleType);
        return R.ok(response);
    }
}
